/**
 * @Author 12629
 * @Date 2022/3/19 9:26
 * @Description：
 */
class Node {
    public int val;
    public Node next;

    /**
     * 构造方法
     * @param val
     */
    public Node(int val){
        this.val = val;
    }
}
public class MyQueue {

    public Node front;//队头
    public Node rear;//队尾

    /**
     * 入队-》尾插法
     * @param val
     */
    public void offer(int val) {
        Node node = new Node(val);
        if(this.front == null) {
            this.front = node;
            this.rear = node;
        }else {
            this.rear.next = node;
            this.rear = node;
        }
    }

    /**
     * 返回队头元素
     * @return
     */
    public int peek() {
        if(isEmpty()) {
            throw new RuntimeException("队列为空！");
        }
        return this.front.val;
    }

    /**
     * 出队
     * @return
     */
    public int poll() {
        if(isEmpty()) {
            throw new RuntimeException("队列为空！");
        }
        int old = this.front.val;
        this.front = this.front.next;
        return old;
    }

    /**
     * 是否为空
     * @return
     */
    public boolean isEmpty() {
        return this.front == null;
    }

}
